package list;

public class Offer18 {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode dummy = new ListNode(-1, head);
        ListNode p = dummy.next;
        ListNode p1 = dummy;
        while (p != null) {
            if (p.val == val) {
                p1.next = p1.next.next;
                break;
            }
            p = p.next;
            p1 = p1.next;
        }

        return dummy.next;
    }
}
